import { defineStore } from "pinia";
import type { LowCodeState, WidgetConfig } from "./typing";

export const useLowCodeConfig = defineStore("low-code", {
  state: (): LowCodeState => {
    return {
      configs: [],
      selectedConfig: null,
    };
  },
  actions: {
    /**删除配置 */
    removeConfig(config: WidgetConfig) {
      const index = this.configs.findIndex((f) => f == config);
      this.configs.splice(index, 1);
      if (this.selectedConfig == config) {
        this.selectedConfig = null;
      }
    },
    /**设置选中配置 */
    setSelectedConfig(config: WidgetConfig) {
      this.selectedConfig = config;
    },
  },
});
